package com.ruoyi.activiti.config;
import org.activiti.engine.*;
import org.apache.batik.util.XMLConstants;
import org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.activiti.image.ProcessDiagramGenerator;
import org.activiti.image.impl.DefaultProcessDiagramGenerator;
import org.activiti.spring.ProcessEngineFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class ActivitiConfig {
    @Bean
    StandaloneProcessEngineConfiguration processEngineConfiguration(DataSource dataSource) {
        StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration();
        standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate("true");
        standaloneProcessEngineConfiguration.setDataSource(dataSource);
//        standaloneProcessEngineConfiguration.setActivityFontName("宋体");
//        standaloneProcessEngineConfiguration.setAnnotationFontName("宋体");
//        standaloneProcessEngineConfiguration.setLabelFontName("宋体");
//        standaloneProcessEngineConfiguration.setProcessDiagramGenerator(customProcessDiagramGenerator);
        return standaloneProcessEngineConfiguration;
    }

//    @Autowired
//    private ICustomProcessDiagramGenerator customProcessDiagramGenerator;

    @Bean
    ProcessEngineFactoryBean processEngineFactoryBean(StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration) {
        ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();
        processEngineFactoryBean.setProcessEngineConfiguration(standaloneProcessEngineConfiguration);
        return processEngineFactoryBean;
    }

    @Bean
    ProcessEngine processEngine(ProcessEngineFactoryBean processEngineFactoryBean) throws Exception {
        return processEngineFactoryBean.getObject();
    }

    @Bean
    HistoryService historyService(ProcessEngine processEngine) {
        return processEngine.getHistoryService();
    }

    @Bean
    TaskService taskService(ProcessEngine processEngine) {
        return processEngine.getTaskService();
    }

    @Bean
    RuntimeService runtimeService(ProcessEngine processEngine) {
        return processEngine.getRuntimeService();
    }

//    @Bean
//    IdentityService identityService(ProcessEngine processEngine) {
//        return processEngine.getIdentityService();
//    }

    @Bean
    ManagementService managementService(ProcessEngine processEngine) {
        return processEngine.getManagementService();
    }

    @Bean
    RepositoryService repositoryService(ProcessEngine processEngine) {
        return processEngine.getRepositoryService();
    }

    @Bean
    ProcessDiagramGenerator processDiagramGenerator() {
        return new DefaultProcessDiagramGenerator();
    }
}
